package com.hg.library.ui.imageview;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.ImageView;

/**
 * Created by ASUS-PC on 2016/5/10.
 */
public class BatteryImg extends ImageView implements BatteryView {

    private int percent;

    private int color = Color.WHITE;

    private Paint paint = new Paint();

    public BatteryImg(Context context, AttributeSet attrs) {
        super(context, attrs);
        paint.setColor(color);
    }

    @Override
    public void setBatteryPercent(int percent) {
        this.percent = percent;
        invalidate();
    }

    @Override
    public int getBatteryPercent() {
        return percent;
    }

    @Override
    public void setColor(int color) {
        this.color = color;
        paint.setColor(color);
        invalidate();
    }

    @Override
    public int getColor() {
        return color;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Rect rect = new Rect(4, 4, (int) (64 / 100f * percent), 24);
        paint.setAntiAlias(true);
        canvas.drawRoundRect(new RectF(rect), 2, 2, paint);
    }
}
